import common from './common';
import XEUtils from "xe-utils";
import VXETable from "vxe-table";
import VxeCellLabel from "../components/VxeCellLabel";

VXETable.renderer.add("vSelectBottom", {
    autofocus: "input.el-input__inner",
    renderEdit(h, renderOpts, params) {
        const {row, column} = params;
        const {attrs, props, filter} = renderOpts;
        let cellValue = XEUtils.get(row, column.property);
        let check = typeof filter === 'undefined' || (typeof filter === 'function' && filter(row, column));
        if (!check) {
            return [h('span', { class: 'vxe-cell--label' }, cellValue)];
        }
        return [
            h("vSelectBottom", {
                attrs: attrs,
                props: Object.assign(props, {params, value: cellValue}),
                on: common.getEditOns(renderOpts, params),
                nativeOn: common.getNativeOns(renderOpts, params)
            })
        ];
    },
    // 可编辑显示模板
    renderCell(h, renderOpts, params) {
        const {row, column} = params;
        const {options} = renderOpts;
        let cellValue = XEUtils.get(row, column.property);
        let value = cellValue;
        if (options) {
            let filter = options.filter(item => cellValue === item.sid);
            if (XEUtils.isArray(filter) && filter.length) {
                value = filter[0].code;
            }
        }
        return [h(VxeCellLabel, {
            props: {
                node: cellValue,
            },
        })];
    }
});
